package service

import (
	"EnjoyWorking/model"
	"EnjoyWorking/utils/storage"
)

type InterfaceDetail struct {}

func (service *InterfaceDetail) Insert(detail *model.InterfaceDetail) error {
	return storage.MySqlDb().Create(detail).Error
}

func (service *InterfaceDetail) Count(path string) (total int64) {
	storage.MySqlDb().Model(&model.InterfaceDetail{}).Where("path = ?", path).Count(&total)
	return
}

func (service *InterfaceDetail) FindList() (int64, []*model.InterfaceDetail, error) {
	var (
		err    error
		total  int64
		result = make([]*model.InterfaceDetail, 0)
	)

	if err = storage.MySqlDb().Model(&model.InterfaceDetail{}).Count(&total).Error; err != nil {
		goto ERR
	}

	if err = storage.MySqlDb().Select("*").Find(&result).Error; err != nil {
		goto ERR
	}
	return total, result, nil
ERR:
	return 0, nil, err
}